package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.dto.customer.UpdateCustomerDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客户管理控制层
 * @Author:Mr.m
 * @Date: 2025-10-17 20:29
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @PutMapping
    public Result updateCustomer(@RequestBody UpdateCustomerDTO dto){
        customerService.updateCustomer(dto);
        return Result.success();
    }

    /**
     * 查询客户id
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryCustomerById(@PathVariable("id") Integer id) {
        log.info("查询客户id:{}",id);
        Customer customer = customerService.queryCustomerById(id);
        return Result.success(customer);
    }

    /**
     * 添加客户
     * @param dto
     * @return
     */
    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto){
        customerService.addCustomer(dto);
        return Result.success();
    }

    /**
     * 客户列表查询
     * @param dto
     * @return
     */
    @GetMapping
    public Result list(CustomerListDTO dto){
        PageResult<CustomerDO> result = customerService.customerList(dto);
        return Result.success(result);
    }
}
